/*
*********************************************************************
* CHwmDataTip.h
*********************************************************************
*/

#if !defined(AFX_CHwmDataTip_H__A874B102_4FF4_11D2_ABF8_00409503D0A9__INCLUDED_)
# define AFX_CHwmDataTip_H__A874B102_4FF4_11D2_ABF8_00409503D0A9__INCLUDED_

# if _MSC_VER >= 1000
#  pragma once
# endif // _MSC_VER >= 1000

// forward declaration
class CHwmDataTipCollection;

// This is an internal class for CHwmDataTip - it holds
// the information for each individual tip
class CHwmDataTipInfo // : public CObject
{
//  DECLARE_DYNCREATE (CHwmDataTipInfo)

    public:
        // Construction
        CHwmDataTipInfo();
        CHwmDataTipInfo(const CHwmDataTipInfo& CopyFrom);
        // Destruction
        virtual ~CHwmDataTipInfo();

        // stores text from source into m_pText
        void StoreText(LPCTSTR pSource);

        // Attributes
    public:
        // The text that will be displayed as a tip; use a "\n" to
        // force a multi-line tip if desired.
        LPSTR    m_pText;

        // position within the parent window so we
        // know when we're in the area.
        CRect    m_TipArea;

        // If non-zero, then this tip is based on a control
        // in a resource.
        int     m_iResource;

        // This is a programmer-assigned ID, it should be
        // unique but that's not enforced.
        int     m_ID;
} ;


// This is the class that's often embedded in the dialog or view,
// containing the individual tool tips
class CHwmDataTip : public CToolTipCtrl
{
        DECLARE_DYNCREATE(CHwmDataTip)

    public:
        // Construction
        CHwmDataTip();
        // Destruction
        virtual ~CHwmDataTip();

//   The Create member must be used before any other member functions
//   or access. Typically used in the "OnInitialUpdate" or "OnInitDialog"
//   or similar function, with pParentWnd set to "this"
        int    Create(CWnd* pParentWnd, DWORD dStyle = 0, CHwmDataTipCollection* pTipCollection = NULL);

        // Attributes
    public:
        // This is the parent window. We need this for base member functions
        // It should be set before calling any of our add-on member functions.
        CWnd   *m_pParent;

        // Array of tip and control information
        CArray<CHwmDataTipInfo*, CHwmDataTipInfo*>
        m_TipArray;

        // Operations
    public:
        // Activates our class and the underlying CToolTipControl and
        // also the parent window.
        void Activate(BOOL bActivate = TRUE);

        // Adds a "control area" to the tool tip, based on a resource ID.
        int AddTip(LPCTSTR pText, int iResource = 0, int iNumber = 0);
        // Adds a control area based on an existing window
        int AddTip(LPCTSTR pText, CWnd *pControl, int iNumber);
        // Adds a control area, with the tip based on a resource string
        int AddTip(int iString, int iResource = 0, int iNumber = 0);
        // Adds a control area based on an existing window
        int AddTip(int iString, CWnd *pControl, int iNumber);

        // Number of tips in the control; index from 0 < Count
        int GetCount(void);

        // Gets a tip by its index
        CHwmDataTipInfo * GetTipIndex(int iNumber);
        // Gets a tip by its resource ID
        CHwmDataTipInfo * GetTipResource(int iResource);
        // gets a tip by its assigned ID number
        CHwmDataTipInfo * GetTipID(int iNumber);

        // Removes a tip, based on its resource ID used in "AddTip"
        int RemoveTipResource(int iResource);
        // Removes a tip based on its ID
        int RemoveTipID(int iNumber);
        // removes a tip based on its index in the array
        int RemoveTipIndex(int iNumber);

        // This is the meat of the DataTip - the request for text is
        // where we test whether we're in a tip area and reply
        // with the appropriate text
        BOOL OnToolTipNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);

        // So the data tip knows that it can remove tip displays
        void OnMouseMove(void);

    private:
        // TRUE if we displayed a tip, but it's not necessarily correct
        // that this flag indicates the real state of the tool tip since
        // the control may have already closed the tip.
        // We use this because some areas, such as a static text box,
        // may not necessarily have the tip automatically closed when
        // the mouse moves.
        BOOL   m_DisplayFlag;
        // to avoid continuous display/hide/display, we ignore
        // mousemove until 100 msecs have passed
        DWORD   m_DisplayTime;

    public:
        // This flag is set by your application or by CHwmDataTipCollection;
        // it tells us whether to process tips or not
        BOOL   m_ActiveFlag;

        // This variable is the collection that this control
        // belongs to.
        CHwmDataTipCollection*
        m_pCollection;
};

// This is a global class, it should be defined as a member of your app
// object or as a standalone object. There can be none, one, or more
// instances of this class. You can register "CHwmDataTip" with this
// class and it will control some global options, such as activation
// and display.
class CHwmDataTipCollection
{
    public:
        // construction
        CHwmDataTipCollection();
        // Destruction
        ~CHwmDataTipCollection();

        // Register an instance of CHwmDataTip with the collection
        int Register(CHwmDataTip* DataTipInfo);
        // de-register an instance with the collection
        int Deregister(CHwmDataTip* DataTipInfo);
        // updates all the items in the collection with new information
        void Update(void);

    public:
        // active flag for all data tips in the collection
        BOOL   m_ActiveFlag;


    protected:
        // Array of tip information
        CArray<CHwmDataTip*, CHwmDataTip*>
        m_TipArray;
} ;

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CHwmDataTip_H__A874B102_4FF4_11D2_ABF8_00409503D0A9__INCLUDED_)
